//
// Created by Administrator on 2024/5/24.
//
#include <Engine.hpp>
#include <Common.hpp>
#include <VkWindow.hpp>
#include <VkDevice.hpp>

namespace NaturalEngine {
    Engine::Engine() {
        // TODO 构造引擎
        //        Log::Trace("Trace");
        //        Log::Debug("Debug");
        //        Log::Info("Info");
        //        Log::Warn("Warn");
        //        Log::Error("Error");
        std::cout << "构造引擎" << std::endl;
    }

    int Engine::Run(const std::vector<std::string> &argv) {
        Engine engine{};
        try {
            engine.Startup();
            engine.MainLoop();
            engine.Cleanup();
        } catch (const std::exception &e) {
            auto error = e.what();
            std::cerr << e.what() << std::endl;
            return EXIT_FAILURE;
        }
        return EXIT_SUCCESS;
    }

    void Engine::Startup() {
        constexpr i32 width = 1280;
        constexpr i32 height = 720;
        const auto window = new VkWindow(width, height);
        const auto device = new VkDevice(*window, *window);
        const auto swapchian = new VkSwapchain(*device, width, height);
        _device.reset(device);
        _window.reset(window);
    }

    void Engine::MainLoop() {
        bool running = true;
        do {
            try {
                running = _window->Update();
                // TODO  running...
                // _logger.Info("Engine run");
            } catch (const std::exception &e) {
                auto error = e.what();
                std::cerr << e.what() << std::endl;
            }
        } while (running);
    }

    void Engine::Cleanup() {

    }
}
